﻿#region

using System.Linq;
using System.Web.Mvc;

#endregion

namespace HouseHoldBudget.Framework.Mvc.Helpers
{
    public static class HtmlHelperEx
    {
        #region Class Methods

        /// <summary>
        ///   Gets the javascript method.
        /// </summary>
        /// <param name="helper"> The helper. </param>
        /// <param name="body"> The body. </param>
        /// <returns> </returns>
        public static string GetJavascriptMethod(this HtmlHelper helper, string body)
        {
            return string.Format("function(){{{0}}}", body);
        }

        /// <summary>
        ///   Gets the javascript method with parameters
        /// </summary>
        /// <param name="helper"> The helper. </param>
        /// <param name="body"> The body. </param>
        /// <param name="parameters"> The parameters. </param>
        /// <returns> </returns>
        public static string GetJavascriptMethod(this HtmlHelper helper, string body, params string[] parameters)
        {
            string parameterString = parameters.Aggregate(string.Empty, (current, param) => current + (param + ","));
            if (parameterString.EndsWith(","))
                parameterString = parameterString.Remove(parameterString.Length - 1, 1);
            return string.Format("function({0}){{{1}}}", parameterString, body);
        }

        #endregion
    }
}